//
//  RGBaseTextShowViewController.m
//  RedGrass
//
//  Created by wukong on 2019/1/29.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//

#import "RGBaseTextShowViewController.h"

@interface RGBaseTextShowViewController ()

@property (strong, nonatomic) UITextView *contentView;

@end

@implementation RGBaseTextShowViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showBackButton];
    [self.customContentView addSubview:self.contentView];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.customContentView).mas_offset(10);
        make.left.mas_equalTo(self.customContentView).mas_offset(15);
        make.right.mas_equalTo(self.customContentView).mas_offset(-15);
        make.bottom.mas_equalTo(self.customContentView).mas_offset(-15);
    }];
    _contentView.text = [self makeLabelStrWithNavTitle];
}

-(NSString *)makeLabelStrWithNavTitle{
    NSString *str = @"";
    if([self.customNavBar.title isEqualToString:@"用户协议"]){
        str = [self readFromTextWithFileName:@"用户协议"];
    }else if([self.customNavBar.title isEqualToString:@"社区自律公约"]){
        str = [self readFromTextWithFileName:@"社区自律公约"];
    }else if([self.customNavBar.title isEqualToString:@"隐私政策"]){
        str = [self readFromTextWithFileName:@"隐私政策"];
    }
    return str;
}

//读取文本文件
-(NSString *)readFromTextWithFileName:(NSString *)fileName{
    NSError *error;
    NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
    NSString *textFieldContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:@"txt"] encoding:enc error:&error];
    NSLog(@"--textFieldContents---%@-----",textFieldContents);
    if (textFieldContents == nil) {
        NSLog(@"---error--%@",[error localizedDescription]);
    }
    return SafeStr(textFieldContents);
   
}


#pragma mark - getter

-(UITextView *) contentView{
    if(!_contentView){
        _contentView = [[UITextView alloc]init];
        _contentView.textColor = [UIColor whiteColor];
        _contentView.font = FONT(customFontName, 15);
        _contentView.editable = NO;
        _contentView.backgroundColor = [UIColor blackColor];
    }
    return _contentView;
}


@end
